//接口地址
var http = "http://192.168.31.9:18080//qyqj/";   //线上地址
var enterpriseSearchResult = new Vue({
  el: '#enterpriseSearchResult',
  components: {
    'left-bar': leftNav
  },
  data: {
    nav_title: "企业画像",
    active_nav: "企业全景",
    entName: '',                 //input框中的公司名称
    searchName: '',              //input框中搜索的公司名称
    getRiskStormEventInfo: [],        //检索出的公司信息
    usedTime: 0,       //检索时间
    loading_show: false, //数据是否在加载中
    navList: [],//导航列表
    searchType: [              //检索类型
      { "id": 0, "typeName": "智能检索" },
      { "id": 1, "typeName": "企业名称" },
      { "id": 2, "typeName": "注册地址" }
    ],
    typeChosed: 0          //选中的检索类型
  },
  created: function () {


    this.init();                //页面初始化
  },
  methods: {
    init: function () {
      this.typeChosed = this.getQueryString("type");
      if (localStorage.getItem('searchCompany') != null) {
        this.entName = localStorage.getItem('searchCompany');
        this.type = localStorage.getItem('type');
      } else {
        this.entName = this.getQueryString("companyName");
        this.typeChosed = this.getQueryString('type');
      }


    },
    getQueryString: function (name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) {
        return decodeURI(r[2]);
      } else {
        return null;
      }
    },
    companyList: function () {
      this.loading_show = true;
      if (this.searchName == "") {
        alert("请输入要搜索的公司名称");
        this.loading_show = false;
        return false;
      }


      localStorage.setItem("searchCompany", this.searchName);
      localStorage.setItem("type", this.typeChosed);
      this.$http.get(http + '/getByKeyword?ORG_NAME=' + this.searchName + '&type=' + this.typeChosed).then(function (res) {
        if (res.data.status == 401) {
          layer.confirm('登录已超时,请重新登录！', { btn: ['确定'], closeBtn: 0 }, function () {
            window.location.href = "http://" + window.location.host + "/business/login.html";
          })
          return false;
        }
        this.getRiskStormEventInfo = res.body[0];

        this.usedTime = res.body[1];
        this.loading_show = false;
      })
    },
    keyUp: function (event) {
      if (event.keyCode == 13) {
        this.companyList()
      } else {
        return false;
      }
    },
    companyDetail: function (companyDetail) {      //跳转到公司详情
      window.location.href = "enterpriseDetail.html?uni_scid=" + companyDetail
    }
  }
})
Vue.prototype.strHtml = function (value) {
  var sv = $.trim(enterpriseSearchResult.entName);
  //console.log(sv);
  svg = sv.split(" ");
  //console.log(svg);
  if (sv) {
    for (var i = 0; i < svg.length; i++) {
      return value.replace(new RegExp(svg[i], 'gi'), '<i>' + svg[i] + '</i>');
    }
  }
}

